#!/usr/bin/python
# -*- coding:UTF8 -*-
import warnings

warnings.filterwarnings("ignore")

# 把函数做为参数传递

# 将字符串中大于等于5的替换成9，小于5的替换成0
import re

strA = '赣A0423FT赣B89B26U赣C7700YV'


def replace(find):
    find_group = find.group()
    if int(find_group) >= 5:
        return '9'
    else:
        return '0'


r = re.sub('\d', replace, strA)
print(r)

phoneNum = '0797-6376998'
r = re.findall('\d+-\d{7,9}', phoneNum)
print(r)

saying = 'life is short,i use Python'
r = re.findall('life(.*)Python', saying)
print(r)
r = re.findall('life(.*?)Python', saying)
print(r)
r = re.findall('life(.+?)Python', saying)
print(r)

# group分组
import re

a = 'A83C72D1D8E67'
r = re.search('\d', a)
print(r)
print(r.group())

a = 'life is short,i use python,i love python'
r = re.search('life(.*)python(.*)python', a)
print(r)
print(r.group())

strA = 'ABC55ABC868张三丰'
r = re.search('([A-Z]*)([0-9]*)([A-Z]*)(\d*)', strA)
# r = re.search('([a-z]*)', strA)
# print(r.group())
# print(r.group(0))
print(r)
print(r.group(2))


import re
a = "123abc456"
print(re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(2))
